#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：PythonData
@File    ：case7_term2.py
@Author  ：朱志文
@Date    ：2021/12/29 19:07
'''
'''江苏科技大学苏州理工学院新闻'''
import requests,os
from lxml import etree
# def main():
#     lst_news, lst_href = [], []
#     for url in [50,51]:
#         for page in range(1,10):
#             resp=requests.get(
#                 url=f'http://justsit.edu.cn/{url}/list{page}.htm',
#                 headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'}
#             )
#             resp.raise_for_status()
#             resp.encoding=resp.apparent_encoding
#             tree=etree.HTML(resp.text)
#             news_a=tree.xpath('//*[@id="wp_news_w6"]/ul/li/div[1]/span[2]/a')
#             news_a_href=tree.xpath('//*[@id="wp_news_w6"]/ul/li/div[1]/span[2]/a/@href')
#             date_span=tree.xpath('//*[@id="wp_news_w6"]/ul/li/div[2]/span')
#             for new,href,date in zip(news_a,news_a_href,date_span):
#                 news_href=f'http://justsit.edu.cn{href}'
#                 lst_news.append(new.text)
#                 lst_href.append(news_href)
#                 # print(new.text,news_href)
#     return lst_news,lst_href
#
# n = 0
# fout = open('suzhou.html', 'w',encoding="utf-8")
# fout.write("<html>")  # 设置输出的html文件的格式
# fout.write("<body>")
# fout.write("<table>")
#
# res_data = {}
# lst_news,lst_href=main()
# # print(lst_href)
# for new,href in zip(lst_news,lst_href):
#
#     res_data['url'] = href
#     res_data['content'] = new
#
#     fout.write("<tr>")
#     fout.write("<td>%s</td>" % res_data['url'])
#     fout.write("<td>%s</td>" % res_data['content'])
#     fout.write("</tr>")
#     n += 1
# print('共发布了%d条信息' % n)
#
# fout.write("</table>")
# fout.write("</body>")
# fout.write("</html>")

'''江苏科技大学苏州理工学院图片'''
# resp=requests.get(
#     url='http://justsit.edu.cn/22/list.htm',
#     headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'}
# )
# resp.raise_for_status()
# resp.encoding=resp.apparent_encoding
# tree=etree.HTML(resp.text)
# img_tree=tree.xpath('//*[@id="wp_content_w6_0"]/p[1]/img')
